﻿using CloudDcPc.Entity;
using CloudDcPc.FuckDlg;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CloudDcPc
{
    /// <summary>
    /// ManageDlg.xaml 的交互逻辑
    /// </summary>
    public partial class ManageDlg : Window
    {
        ObservableCollection<User> all_User = null;
        ObservableCollection<Gz> all_Gz = null;
        ObservableCollection<Tab> all_Tab = null;
        ObservableCollection<MyMenu> all_MyMenu = null;
        ObservableCollection<Together> all_Together = null;
        ObservableCollection<MenuType> all_MenuType = null;
        int index;
        public ManageDlg()
        {
            InitializeComponent();


            if (App.user.Type != 4)
            {
                all_User = App.UserBean.GetAllUserNotZJL();   //不显示总经理
            }
            else
            {
                all_User = App.UserBean.GetAllUser();
            }
            
            lw_user_manage.ItemsSource = all_User;

            all_Gz = App.GzBean.GetAllGz();
            lw_gz_manage.ItemsSource = all_Gz;

            all_Tab = App.TabBean.GetAllTab();
            lw_tab_manage.ItemsSource = all_Tab;

            all_MyMenu = App.MyMenuBean.GetAllMyMenu();
            lw_mymenu_manage.ItemsSource = all_MyMenu;

            all_Together = App.TogetherBean.GetAllTogether();
            lw_together_manage.ItemsSource = all_Together;

            all_MenuType = App.MenuTypeBean.GetAllMenuType();
            lw_menutype_manage.ItemsSource = all_MenuType;
        }

        private void UserManageListDC(object sender, MouseButtonEventArgs e)
        {

            index = all_User.IndexOf((User)lw_user_manage.SelectedItem);
            UserEditDlg userEditDlg = new UserEditDlg(all_User[index]);
            userEditDlg.ShowDialog();
            if (userEditDlg.DialogResult == true)
            {
                all_User.RemoveAt(index);
            }
        }

        private void GzManageListDC(object sender, MouseButtonEventArgs e)
        {

            index = all_Gz.IndexOf((Gz)lw_gz_manage.SelectedItem);
            GzEditDlg userEditDlg = new GzEditDlg(all_Gz[index]);
            userEditDlg.ShowDialog();
            if (userEditDlg.DialogResult == true)
            {
                all_Gz.RemoveAt(index);
            }
        }

        private void TabManageListDC(object sender, MouseButtonEventArgs e)
        {

            index = all_Tab.IndexOf((Tab)lw_tab_manage.SelectedItem);
            TabEditDlg tabEditDlg = new TabEditDlg(all_Tab[index]);
            tabEditDlg.ShowDialog();
            if (tabEditDlg.DialogResult == true)
            {
                all_Tab.RemoveAt(index);
            }
        }

        private void MyMenuManageListDC(object sender, MouseButtonEventArgs e)
        {

            index = all_MyMenu.IndexOf((MyMenu)lw_mymenu_manage.SelectedItem);
            MyMenuEditDlg myMenuEditDlg = new MyMenuEditDlg(all_MyMenu[index]);
            myMenuEditDlg.ShowDialog();
            all_MyMenu = App.MyMenuBean.GetAllMyMenu();   //已经刷新了，所以不能再像其他的RemoveAt 了
            lw_mymenu_manage.ItemsSource = all_MyMenu;
        }
        private void TogetherManageListDC(object sender, MouseButtonEventArgs e)
        {

            index = all_Together.IndexOf((Together)lw_together_manage.SelectedItem);
            TogetherEditDlg togetherEditDlg = new TogetherEditDlg(all_Together[index]);
            togetherEditDlg.ShowDialog();

            if (togetherEditDlg.DialogResult == true)
            {
                all_Together.RemoveAt(index);
            }
        }
        private void MenuTypeManageListDC(object sender, MouseButtonEventArgs e)
        {

            index = all_MenuType.IndexOf((MenuType)lw_menutype_manage.SelectedItem);
            MenuTypeEditDlg menuTypeEditDlg = new MenuTypeEditDlg(all_MenuType[index]);
            menuTypeEditDlg.ShowDialog();
            if (menuTypeEditDlg.DialogResult == true)
            {
                all_MenuType.RemoveAt(index);
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            UserAddDlg userAddDlg = new UserAddDlg(all_User);
            userAddDlg.ShowDialog();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            GzAddDlg userAddDlg = new GzAddDlg(all_Gz);
            userAddDlg.ShowDialog();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            TabAddDlg tabAddDlg = new TabAddDlg(all_Tab);
            tabAddDlg.ShowDialog();
        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            MyMenuAddDlg myMenuAddDlg = new MyMenuAddDlg(all_MyMenu);
            myMenuAddDlg.ShowDialog();
            all_MyMenu = App.MyMenuBean.GetAllMyMenu();
            lw_mymenu_manage.ItemsSource = all_MyMenu;
        }

        private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            TogetherAddDlg togetherAddDlg = new TogetherAddDlg(all_Together);
            togetherAddDlg.ShowDialog();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MenuTypeAddDlg menuTypeAddDlg = new MenuTypeAddDlg(all_MenuType);
            menuTypeAddDlg.ShowDialog();
        }
    }
}
